

#Goal for this example:
# build a collection of ptx files, and than do the following with them:
# 1. Verify that we can dump the paths to the files into a generated file
# 2. Take the generated ptx files, run them through bin2c and then embed
#    the generated header into a new executable
# 3. Verify that we can install the output of the ptx generation as
#    EXPORTED targets ( with associated files )

#We are going to need a wrapper around bin2c for multiple reasons
# 1. bin2c only converts a single file at a time
# 2. bin2c has only standard out support, so we have to manually
# redirect to a cmake buffer
# 3. We want to pack everything into a single output file, so we
# need to also pass the --name option

add_library(CudaPTXObjects OBJECT kernelA.cu kernelB.cu)
set_property(TARGET CudaPTXObjects PROPERTY CUDA_PTX_COMPILATION ON)

add_custom_command(
  OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/embeded_objs.h"
  COMMAND ${CMAKE_COMMAND}
  "-DOBJECTS:STRING=\"$<TARGET_OBJECTS:CudaPTXObjects>\""
  "-DOUTPUT:FILEPATH=\"${output_file}\""
  -P ${CMAKE_CURRENT_SOURCE_DIR}/bin2c_wrapper.cmake
  DEPENDS CudaPTXObjects
  COMMENT "Converting Object files to a C header"
  )

#Setup the dependency chain for the
add_custom_target(CUDABin2C
  DEPENDS ${output_file}
  )
add_dependencies(CUDABin2C CudaPTXObjects)
add_library(ConsumeBin2C SHARED ${output_file} importer.cu)
target_include_directories(ConsumeBin2C PRIVATE ${CMAKE_CURRENT_BINARY_DIR})


#Verify that we can install object targets properly
install(TARGETS CudaPTXObjects ConsumeBin2C
   EXPORT cudamixedobjs
   RUNTIME DESTINATION bin
   LIBRARY DESTINATION lib
   OBJECTS DESTINATION objs
   )
install(EXPORT cudamixedobjs DESTINATION lib/cudamixedobjs)
